/*
   Copyright 2009 Bloo. All Rights Reserved.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package org.youtensils.www.client.browser;

/**
 * Provides support for detecting browser capabilities by wrapping around JavaScript libraries.
 * @author Bobby Soares
 */
public class BrowserCapabilities {
	/**
	 * Retrieves the version of the active JRE, if any.
	 * @return an array containing the major and minor version numbers
	 */
	public static int[] getJavaVersion(){
		String jre = detectJavaVersion();
		if(jre == null || jre.equals("")) return new int[]{ 0, 0, 0, 0 };
		String[] jreVersions = jre.split(",");
		if(jreVersions.length != 4) return new int[]{ 0, 0, 0, 0 };
		try{
			return new int[]{
				new Integer(jreVersions[0]).intValue(),
				new Integer(jreVersions[1]).intValue(),
				new Integer(jreVersions[2]).intValue(),
				new Integer(jreVersions[3]).intValue()
			};
		}catch(Exception x){}
		return new int[]{ 0, 0, 0, 0 };
	}
	/**
	 * A native wrapper to a JavaScript function which detects the version of the active JRE, if any.
	 * @return a string containing the major and minor version numbers, comma delimited
	 */
	private native static String detectJavaVersion()/*-{
        return $wnd.PluginDetect.getVersion('Java') || '0,0,0,0';
	}-*/;
}
